/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.meducated.sim.model;

import com.meducated.sim.model.def.DefaultModel;
import com.google.appengine.api.utils.SystemProperty;
import com.meducated.core.model.controllers.Slope;
import java.util.HashMap;
import java.util.Map;

/**
 * A standalone demonstration of the core model
 *
 * I'VE WRITTEN THIS TO SHOW HOW THE MODEL CLASSES WOULD BE USED TOGETHER WHICH
 * HELPS TO THINK ABOUT HOW TO IMPLEMENT ALL THIS
 *
 * @author Carina
 */
public class RunStandaloneDemo {

    /**
     * Runs a
     *
     * @param args
     */
    public static void main(String[] args) {
        /* if (SystemProperty.environment.value()
         == SystemProperty.Environment.Value.Development) {
         System.out.println("Running on development server...");
         // The app is running on dev App Engine...
         }*/

        DefaultModel model = new DefaultModel();

        final Property<Double> hr = new Property<Double>("HR", "Heart rate", "/min", 70d);
        final Property<Double> sv = new Property<Double>("SV", "Stroke volume", "l/min", 0.070);
        final Property<Double> co = new Property<Double>("CO", "Cardiac output", "l/min", 0d);
        final Property<Double> tpr = new Property<Double>("TPR", "Total peripheral resistance", "mmHg/(mL/min)", 20d); // in mmHg min/l.
        final Property<Double> map = new Property<Double>("MAP", "Mean arterial blood pressure", 0d);


        
        hr.getConnector().setIntegrator(new SumIntegrator());
        
        model.add(sv);
        model.add(hr);

        co.getConnector().putDependency(sv);
        co.getConnector().putDependency(hr);
        model.add(co);
       
        co.getConnector().setIntegrator(new PropertyIntegrator<Double>() {
            @Override
            public Double integrate(Property<Double> property, double t, double dt, Double value) {
                return hr.getValue() * sv.getValue();
            }
        });

        map.getConnector().putDependency(tpr);
        map.getConnector().putDependency(co);
        
        map.getConnector().setIntegrator(new PropertyIntegrator<Double>() {
            @Override
            public Double integrate(Property<Double> property, double t, double dt, Double value) {
                return tpr.getValue() * co.getValue();
            }
        });
        model.add(tpr);
        model.add(map);
        
        
        
        Slope lowerhr = new Slope(-0.2);
        model.add(lowerhr, hr);


        /*
         model.add(new BasicSensor <Double> (hr, Timing.seconds(5)) {
         public void valueChanged(Property <Double> prop) {
         if(prop.getValue() < 40) {
         System.out.println("I feel a little dizzy...");
         }
         else if(prop.getValue() < 20) {
         System.out.println("I don't feel well!!!");
         }
         else if(prop.getValue() < 0) {
         System.out.println("hmnn...n.......");
         }
         }
                
         ));*/


        model.add(new Periodic() {
            @Override
            public void run(double t) {
                System.out.println(hr.toString());
                System.out.println(sv.toString());
                System.out.println(co.toString());
                System.out.println(tpr.toString());
                System.out.println(map.toString());
                System.out.println("-----------------");
            }

            public double getInterval() {
                return 1d;
            }
        });




        model.runStandaloneFor(Timing.seconds(30));
       
    }
}
